package com.zx.controller.dj;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zx.model.dj.PriceRecord;
import com.zx.service.dj.PriceManageService;

/**
 * 
 * @author yt
 *
 */
@Controller
@RequestMapping("price")
public class PriceManageController {

	@Autowired
	PriceManageService priceManageService;

	@RequestMapping("toSetDiscount")
	public String toSetDiscount(Model model) {
		return "dj/SetDiscount";
	}

	@RequestMapping("toSetSpecial")
	public String toSetSpecial(Model model) {
		return "dj/SetSpecial";
	}

	/**
	 * 折扣设置
	 * 
	 * @param model
	 * @param list 
	 * @return
	 */
	@RequestMapping("setDiscount")
	public String setDiscount(Model mod, String smodel, String scolor, BigDecimal lastprice, BigDecimal sdiscount, BigDecimal nowprice, Object list) {
		try {
	        mod.addAttribute("smodel", smodel);
	        mod.addAttribute("scolor", scolor);
	        mod.addAttribute("sdiscount", sdiscount);
			priceManageService.uptDiscount(mod, smodel, scolor, lastprice, sdiscount, nowprice);
			mod.addAttribute("result", "1");
		} catch (Exception e) {
			mod.addAttribute("result", "0");
			e.printStackTrace();
		}

		return "dj/SetDiscount";
	}

	/**
	 * 特价设置
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping("setSpecial")
	public String setSpecial(Model mod, String pmodel, String pcolor, BigDecimal pnowprice) {
		try {
	        mod.addAttribute("pmodel", pmodel);
	        mod.addAttribute("pcolor", pcolor);
	        mod.addAttribute("pnowprice", pnowprice);
			priceManageService.uptSpecial(mod, pmodel, pcolor, pnowprice);
			mod.addAttribute("result", "1");
		} catch (Exception e) {
			mod.addAttribute("result", "0");
			e.printStackTrace();
		}

		return "dj/SetSpecial";
	}
}